package com.apes.auto.car.service;

import com.apes.auto.car.model.AutoEmissionStandard;
import com.apes.auto.car.repository.AutoEmissionStandardRepository;
import com.apes.framework.api.DomainService;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName AutoCategoryService
 * @Description TODO
 * @Author pengyb
 * @Date 2019/7/12 11:33
 * @Version 1.0
 **/
@Service("autoEmissionStandardService")
public class EmissionStandardService extends DomainService {

    @Autowired
    AutoEmissionStandardRepository autoEmissionStandardRepository;

    public AutoEmissionStandard save(SimpleRequest request) {
        AutoEmissionStandard autoEmissionStandard = request.getO(AutoEmissionStandard.class);
        return autoEmissionStandardRepository.save(autoEmissionStandard);
    }

    public String delete(SimpleRequest request) {
        String id = request.get("id");
        Integer versions = request.get("version");
        AutoEmissionStandard autoEmissionStandard = request.getO(AutoEmissionStandard.class);
        if (autoEmissionStandard == null) throw new RuntimeException("排放标准【"+ id +"】在系统中不存在。");
        if (autoEmissionStandard.getVersion() != versions) throw new RuntimeException("记录已更新或已删除，请重新提交！");
        autoEmissionStandardRepository.delete(autoEmissionStandard);
        return "删除成功";
    }

}
